package com.example.recyclerViewDemo

import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView

/**
 * @Author Xzh
 * @Date 2024/12/16
 * @Description
 */
class MyAdapter(val data: List<Drawable>) : RecyclerView.Adapter<MyAdapter.mViewHodler>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): mViewHodler {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item,parent,false)
        return mViewHodler(view)
    }

    override fun getItemCount(): Int {
        return data.size
    }

    override fun onBindViewHolder(holder: mViewHodler, position: Int) {
       holder.image.setImageDrawable(data[position])
    }


    class mViewHodler(view : View) : RecyclerView.ViewHolder(view){
        val image: ImageView = view.findViewById(R.id.imageView)
    }
}

